home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / h / tok2h.awk < prev    next >
Encoding:
AWK Script  |  1996-09-27  |  3.5 KB  |  105 lines

  1. BEGIN {
  2.   #{{{}}}
  3. #  {{{  gen filenames
  4.   tokout="token.h"
  5.   lgout="codelg.h"
  6. #  }}}
  7. #  {{{  print auto-gen-marks
  8.   print("/* This file is generated automatically by awk -f tok2h.awk */\n/* containing command types for OCL token */") >lgout
  9.   print("/* This file is generated automatically by awk -f tok2h.awk */\n/* containing automatically generated OCL tokens (origami) */") >tokout
  10. #  }}}
  11. #  {{{  print start of token type
  12.   print("#ifndef TOKEN_H_READ") >tokout
  13.   print("#  define TOKEN_H_READ") >tokout
  14.   print("   typedef enum") >tokout
  15.   print("    { keytaball = -4,") >tokout
  16.   print("      keytabknb = -3,") >tokout
  17.   print("      keytabend = -2,") >tokout
  18.   print("      keytabcont= -1,") >tokout
  19.   print("      O_NOP=(1<<BITS_P_CHAR),") >tokout
  20. #  }}}
  21. #  {{{  print command type
  22.   print("typedef enum") >lgout
  23.   print(" { COM=0,\t/* simple command\t\t\t*/") >lgout
  24.   print("   COM_C,\t/* command with 1 char argument\t\t*/") >lgout
  25.   print("   COM_I,\t/* command with 1 int argument\t\t*/") >lgout
  26.   print("   COM_A,\t/* command with a adress\t\t*/") >lgout
  27.   print("   COM_II,\t/* command with 2 int arguments\t\t*/") >lgout
  28.   print("   COM_P,\t/* command with a prompt\t\t*/") >lgout
  29.   print("   COM_IP,\t/* command with 1 int and prompt\t*/") >lgout
  30.   print("   COM_IIP\t/* command with 2 int and prompt\t*/") >lgout
  31.   print(" } COM_TYPES;") >lgout
  32.   print("#ifdef CODE_LG_ARRAY") >lgout
  33.   print("  COM_TYPES cmd_type[] =\n   { COM,\t\t/* O_NOP */") >lgout
  34. #  }}}
  35. #  {{{  init fixed cmd arg range
  36.   cmd_range=8
  37. #  }}}
  38.   check=0
  39. }
  40. #{{{  set fixed cmd arg range
  41. /^#define +FIXED_COMMAND_RANGE/ {
  42.   cmd_range=$3
  43. }
  44. #}}}
  45. #{{{  skip comments
  46. $0~/^#/ { next }
  47. #}}}
  48. #{{{  OCL-var handling
  49. #}}}
  50. #{{{  set types for command and fixed command
  51. $3=="COM" || $3=="COM_I" || $3=="COM_II" || $3=="COM_P" || $3=="COM_IP" || $3=="COM_IIP" || $3=="COM_C" { typ=$3;fix_typ="" }
  52. $3=="COM_A" { typ="COM_A";fix_typ="COM" }
  53. $3=="COM_ID" { typ="COM_II";fix_typ="COM_I"; }
  54. $3=="COM_D" { typ="COM_I";fix_typ="COM"; }
  55. #}}}
  56. #{{{  print token and cmd type
  57. $3!="OCL-KEY" && $3!="OPP-KEY" {
  58.    if (fix_typ!="") {
  59.      if (def=="")
  60.         def="#  define RANGE_ADD ("$1"_0-"$1")\n"
  61.      def=def"#  define CASES_"$1" "
  62.      for (i=cmd_range;i>0;i--) {
  63.         print("      "$1"_M"i",") >tokout
  64.         print("     "fix_typ",\t\t/* "$1"_M"i" */") >lgout
  65.         def=def"case "$1"_M"i":"
  66.      }
  67.      for (i=0;i<=cmd_range;i++) {
  68.         print("      "$1"_"i",") >tokout
  69.         print("     "fix_typ",\t\t/* "$1"_"i" */") >lgout
  70.         def=def"case "$1"_"i":"
  71.      }
  72.      def=def"\n"
  73.    }
  74.    print("      "$1",") >tokout
  75.    print("     "typ",\t\t/* "$1" */") >lgout
  76. }
  77. #}}}
  78. #{{{  handle check sum
  79. $3=="COM"     { check = ( check +   1 ) % 1024 }
  80. $3=="COM_C"   { check = ( check +   2 ) % 1024 }
  81. $3=="COM_I"   { check = ( check +   4 ) % 1024 }
  82. $3=="COM_A"   { check = ( check +  16 ) % 1024 }
  83. $3=="COM_II"  { check = ( check +  32 ) % 1024 }
  84. $3=="COM_ID"  { check = ( check +  64 ) % 1024 }
  85. $3=="COM_P"   { check = ( check + 128 ) % 1024 }
  86. $3=="COM_IP"  { check = ( check + 256 ) % 1024 }
  87. $3=="COM_IIP" { check = ( check + 512 ) % 1024 }
  88. #}}}
  89. END {
  90. #  {{{  print end of token type
  91.   print("      DUMMYTOKEN\n    } TOKEN;") >tokout
  92.   print("#  define TOKEN_TYPE_CHECK "0+check) >tokout
  93.   print("#  define FIXED_COMMAND_RANGE "0+cmd_range) >tokout
  94.   printf(def) >tokout
  95.   print("#endif") >tokout
  96. #  }}}
  97. #  {{{  end command type information
  98.   print("     COM") >lgout
  99.   print("   };") >lgout
  100.   print("#else") >lgout
  101.   print("   extern COM_TYPES cmd_type[];") >lgout
  102.   print("#endif") >lgout
  103. #  }}}
  104. }
  105.